package com.hpeu_12.day1224;

import java.util.Arrays;

/**
 * Arrays工具类使用
 * @author clover
 *
 */
public class ArraysDemo {
	public static void main(String[] args) {
		//sort()方法：用于对数组排序（除了boolean类型都可以）
		int[] arr = {2,5,6,8,1,9};
		String[] str = {"a","d","e","b","c"};
		Arrays.sort(arr);
		Arrays.sort(str);
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i]+" ");
		}
		System.out.println();
		for (int j = 0; j < str.length; j++) {
			System.out.print(str[j]+" ");
		}
		System.out.println();
		
		//copyof()方法：把一个数组复制出一个新数组(新数组的长度为length)
		int[] arr1 = {2,3,5,1,6,9};
		int[] arr2 = Arrays.copyOf(arr1,arr1.length);
		for (int i = 0; i < arr2.length; i++) {
			System.out.print(arr2[i]+" ");
		}
		System.out.println();
		
		//toString()方法：把数组转换成字符串输出
		System.out.println(Arrays.toString(arr1));
		
		//binarySearch()方法：找到元素在数组中的下标(索引)
		String[] str2 = {"a","b","c","d","e"};
		int index = Arrays.binarySearch(str2, "e");
		System.out.println("该元素在数组中的索引为："+index);
		
		//fill()方法：把整个数组里的每一个元素的值进行替换为value
		int[] arr3 = {1,2,3,4,5};
		//Arrays.fill(arr3, 6);
		Arrays.fill(arr3, 0, 1, 6);
		System.out.println(Arrays.toString(arr3));

	}
}
